import { EventSender } from "../flash/EventSender";
import { Context } from "./Context";
import { SRMICall } from "./SRMICall";
import { SerializeStream } from "../../Framework/Serialize/SerializeStream";
import { ERMIDispatchStatus } from "./ERMIDispatchStatus";
import { Exception } from "../../Framework/Util/Exception";
import { RMIDispatcher } from "./RMIDispatcher";
import { SIdentity } from "./SIdentity";
//class RMIObject

export class RMIObject extends EventSender {
  constructor(protected _response?: Function, protected _ex?: Function) {
    super();
  }

  public __dispatch(
    arg1: Context,
    arg2: SRMICall,
    arg3: SerializeStream,
    arg4: SerializeStream
  ): ERMIDispatchStatus {
    return ERMIDispatchStatus.DispatchOK;
  }

  public __response(arg1: SerializeStream): void {}

  public cdeException(arg1: Exception): void {
    if (null != this._ex) {
      this._ex.call(this, arg1);
      return;
    }
    arg1.method = "";
    if (this._identity) {
      arg1.method = this._identity.name + ":";
    } else {
      // trace("method:" + arg1.method + " callFunction:" + this._callFunction);
    }
    arg1.method += this._callFunction;
    RMIDispatcher.getInstance().dispatchErrorEvent(arg1);
    return;
  }

  public get identity(): SIdentity {
    return this._identity;
  }

  public set identity(arg1: SIdentity) {
    if (this._identity == null) {
      this._identity = new SIdentity();
    }
    this._identity.name = arg1.name;
    return;
  }

  public set name(arg1: string | null) {
    if (this._identity == null) {
      this._identity = new SIdentity();
    }
    this._identity.name = arg1!;
    return;
  }

  public get name(): string | null {
    if (this._identity) {
      return this._identity.name;
    }
    return null;
  }

  public set callFunction(arg1: string) {
    this._callFunction = arg1;
    return;
  }

  public get usedTimer(): number {
    return this._usedTimer;
  }

  public set usedTimer(arg1: number) {
    this._usedTimer = arg1;
    return;
  }

  public get callFunction(): string {
    return this._callFunction;
  }

  private _identity!: SIdentity;

  private _callFunction!: string;

  private _usedTimer!: number;

  public userObject: any;
}
